package com.yunhe.control;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.yunhe.bean.Board;
import com.yunhe.service.GoodsBoardService;

/**
 * Servlet implementation class getBoardFenYe
 */
/*@WebServlet(name = "getBoardFenYe.do", urlPatterns = { "/getBoardFenYe.do" })*/
@WebServlet("/getBoardFenYe.do")
public class getBoardFenYe extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public getBoardFenYe() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String pages = request.getParameter("pages");//页码
		int i = 0;
		if(pages == null) {
			i=0;//第一页
			
		}else {
			i = Integer.parseInt(pages);//所在页
		}
		
		List<Board> list = new GoodsBoardService().getSeparaboard(i*5);//将每页的数据存在一个集合中
		int sum = new GoodsBoardService().getboard().size();//数据总条数
		
		int sumPage = sum%5==0?sum/5:sum/5+1;//总页数zongtiao%3==0?zongtiao/3:zongtiao/3+1
		
		System.out.println(sumPage);
		System.out.println(sum);
		request.getSession().setAttribute("currpage", pages);
		request.getSession().setAttribute("sum", sum);
		request.getSession().setAttribute("sumPage", sumPage-1);
		request.getSession().setAttribute("list", list);
		request.getRequestDispatcher("hou/goods-classify.jsp").forward(request, response);
		//response.sendRedirect("hou/goods-classify.jsp");
	}

}
